package com.yjt.fresh.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseResultEntity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.api.ApiSubmitSuggestion;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.utils.PreferenceManager;
import com.yjt.fresh.widget.CustomToast;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 意见反馈
 * Created by mcc on 2018/7/21.
 */

public class AtyAdvice extends BaseSimpleActivity {
    @BindView(R.id.back)
    RelativeLayout mBack;
    @BindView(R.id.edtAppAtyAdvice)
    EditText mEdtAdvice;
    @BindView(R.id.btnAppAtyAdviceSubmit)
    Button mBtnSubmit;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_advice;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initEvent() {
        mBtnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEdtAdvice.getText().toString())){
                    CustomToast.showLong("请输入建议");
                    return;
                }else {
                    submitAdvice();
                }
            }
        });

        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    HttpOnNextListener<BaseResultEntity> mListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            CustomToast.showLong("提交成功");
            finish();
        }

        @Override
        public void failed(String massage) {
            CustomToast.showLong(massage);
        }

        @Override
        public void onReLogin() {
            toLogin();
        }
    };
    private void submitAdvice() {
        ApiSubmitSuggestion apiSubmitSuggestion = new ApiSubmitSuggestion(mListener,mContext,true,false,true);
        Map<String,Object> map = new HashMap<>();
        map.put("CONTENT",mEdtAdvice.getText().toString());
        map.put("SESSION_ID", PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        apiSubmitSuggestion.setMap(map);
        HttpManager.getInstance().doHttpDeal(apiSubmitSuggestion);
    }

}
